//
// Created by casdon on 2024/8/1.
//

#ifndef CIOT_UTILS_H
#define CIOT_UTILS_H

#include "types.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum Ciot_log_level_e
{
    Ciot_log_level_all = 0,
    Ciot_log_level_info,
    Ciot_log_level_success,
    Ciot_log_level_warning,
    Ciot_log_level_error,
    Ciot_log_level_fatal,
    Ciot_log_level_debug,

    Ciot_log_level_none

} Ciot_log_level;

CIOT_API
Ciot_log_level ciot_log_set_level( Ciot_log_level level );

CIOT_API
Ciot_res ciot_log( Ciot_log_level lv, const char * msg, ... );

#if CIOT_FOR_RELEASE
#define ciot_log_info( msg, ... )
#else
#define ciot_log_info( msg, ... )  \
    ciot_log( Ciot_log_level_info, msg, ##__VA_ARGS__ )
#endif

#define ciot_log_success( msg, ... )  \
    ciot_log( Ciot_log_level_success, msg, ##__VA_ARGS__ )

#if CIOT_FOR_RELEASE
#define ciot_log_warning( msg, ... )
#else
#define ciot_log_warning( msg, ... )  \
    ciot_log( Ciot_log_level_warning, msg, ##__VA_ARGS__ )
#endif

#define ciot_log_error( msg, ... )  \
    ciot_log( Ciot_log_level_error, msg, ##__VA_ARGS__ )

#define ciot_log_fatal( msg, ... )  \
    ciot_log( Ciot_log_level_fatal, msg, ##__VA_ARGS__ )

#if CIOT_FOR_RELEASE
#define ciot_log_debug( msg, ... )
#else
#define ciot_log_debug( msg, ... )  \
    ciot_log( Ciot_log_level_debug, msg, ##__VA_ARGS__ )
#endif
Ciot_res ciot_hex_log( Ciot_log_level lv, const unsigned char * data, size_t len );

#if CIOT_FOR_RELEASE
#define ciot_hex_log_info( data, len )
#else
#define ciot_hex_log_info( data, len )  \
    ciot_hex_log( Ciot_log_level_info, data, len )
#endif

#define ciot_hex_log_success( data, len )  \
    ciot_hex_log( Ciot_log_level_success, data, len )

#if CIOT_FOR_RELEASE
#define ciot_hex_log_warning( data, len )
#else
#define ciot_hex_log_warning( data, len )  \
    ciot_hex_log( Ciot_log_level_warning, data, len )
#endif

#define ciot_hex_log_error( data, len )  \
    ciot_hex_log( Ciot_log_level_error, data, len )

#define ciot_hex_log_fatal( data, len )  \
    ciot_hex_log( Ciot_log_level_fatal, data, len )

#if CIOT_FOR_RELEASE
#define ciot_hex_log_debug( data, len )
#else
#define ciot_hex_log_debug( data, len )  \
    ciot_hex_log( Ciot_log_level_debug, data, len )
#endif

#ifndef CIOT_HEX_LOG_INT
#define CIOT_HEX_LOG_INT 0
#endif

#ifndef CIOT_HEX_LOG_HEX
#define CIOT_HEX_LOG_HEX 1
#endif

#ifndef CIOT_HEX_LOG_CHAR
#define CIOT_HEX_LOG_CHAR 0
#endif





#ifdef __cplusplus
}
#endif

#endif //CIOT_UTILS_H
